package models

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Username string `gorm:"type:varchar(255);not null"`
	Password string `gorm:"type:varchar(255);not null"`
	Email    string `gorm:"type:varchar(255);not null"`
	Tel      string `gorm:"type:char(11);not null"`
	IsReal   int    `gorm:"type:tinyint(1);not null"`
}

type UsersReals struct {
	gorm.Model
	UserID   int    `gorm:"type:int(11);not null"`
	RealName string `gorm:"type:varchar(255)"`
	IDCard   string `gorm:"type:varchar(255)"`
}

func (u *User) FindUser(db *gorm.DB, tel string) error {
	return db.Where("tel = ?", tel).First(u).Error
}

func (u *User) UserAdd(db *gorm.DB) error {
	return db.Create(&u).Error
}

func (u *UsersReals) RealAdd(db *gorm.DB) error {
	return db.Create(&u).Error
}

func (u *User) UpdateRealStatus(db *gorm.DB, userID int64) error {
	return db.Where("id =?", userID).Updates(&u).Error
}

func (u *UsersReals) UpdateReal(db *gorm.DB, userID int64) error {
	return db.Where("user_id = ?", userID).Updates(&u).Error
}
